package com.gem.netty.message;

import com.gem.enums.MessageColorType;
import com.gem.factory.game.GameFactory;
import com.gem.factory.user.UserFactory;
import com.gem.netty.entity.ClientContent;
import com.gem.netty.session.GroupSession;
import com.gem.netty.session.GroupSessionFactory;
import com.gem.utils.R;
import io.netty.channel.Channel;

import java.util.List;

/**
 * Author: Xhy
 * CreateTime: 2022-09-21 13:16
 * 聊天
 */
public class ChatRoomMessage implements Message{


    // 向房间内发送消息
    @Override
    public void handler(ClientContent content) {
        String roomId = content.getRoomId();
        String userId = content.getSendId();
        GroupSession groupSession = GroupSessionFactory.getGroupSession();
        List<Channel> members = groupSession.getMembersChannel(roomId);
        GameFactory.notifyUsers(members,R.ok().data("color", MessageColorType.SEND_MESSAGE.type).message(UserFactory.get(userId) + ":" +content.getContent().getMessage()).type(content.getType()),roomId);
    }
}
